package com.songlanyun.modules.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

/**
 * 广告错误异常枚举类
 */
public enum BbsException implements IntegerEnum<Integer> {

    BBS_THEME_NAME_REPEAT(150011, "话题名称重复"),
    BBS_THEME_NOT_EXISTS(150012, "话题不存在"),
    BBS_THEME_TITLE_UNIQUE(150013, "话题已存在"),

    OPUS_NOT_EXISTS(151011, "作品不存在"),
    OPUS_AUDIT_PARAMETER_PARTIAL(151012, "作品审核参数不全"),
    OPUS_STICK_PARAMETER_PARTIAL(151013, "作品置顶参数不全"),
    OPUS_ALREADY_AUDIT(151014, "该作品已审核，不能再次审核"),

    ALREADY_LIKE(160001, "已经点赞过,不能再点赞"),

    ARTICLE_NOT_EXIST(161001, "文章不存在"),
    PARAMETER_IS_NOT_COMPLETE(161002, "必要参数不全"),
    ARTICLE_ALREADY_SOLD(161003, "文章已下架"),

    COURSE_CLASSIFY_NOT_EXIST(162001, "课程分类不存在"),
    COURSE_CLASSIFY_NAME_UNIQUE(162002, "课程分类已存在"),
    COURSE_CLASSIFY_CREATE_ARTICLE(162003, "该课程分类下已创建了课程"),

    ;


    private Integer code;

    private String msg;

    BbsException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @JsonCreator
    public static BbsException getByCode(int code) {
        for (BbsException value : BbsException.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
